


namespace Nadine{


	/* Triangle/triangle intersection test routine,
	 * by Tomas Moller, 1997.
	 * See article "A Fast Triangle-Triangle Intersection Test",
	 * Journal of Graphics Tools, 2(2), 1997
	 * updated: 2001-06-20 (added line of intersection)
	 *
	 * int tri_tri_intersect(float V0[3],float V1[3],float V2[3],
	 *                       float U0[3],float U1[3],float U2[3])
	 *
	 * parameters: vertices of triangle 1: V0,V1,V2
	 *             vertices of triangle 2: U0,U1,U2
	 * result    : returns 1 if the triangles intersect, otherwise 0
	 *
	 * Here is a version withouts divisions (a little faster)
	 * int NoDivTriTriIsect(float V0[3],float V1[3],float V2[3],
	 *                      float U0[3],float U1[3],float U2[3]);
	 * 
	 * This version computes the line of intersection as well (if they are not coplanar):
	 * int tri_tri_intersect_with_isectline(float V0[3],float V1[3],float V2[3], 
	 *				        float U0[3],float U1[3],float U2[3],int *coplanar,
	 *				        float isectpt1[3],float isectpt2[3]);
	 * coplanar returns whether the tris are coplanar
	 * isectpt1, isectpt2 are the endpoints of the line of intersection
	 */
	int coplanar_tri_tri(float N[3],float V0[3],float V1[3],float V2[3],
						 float U0[3],float U1[3],float U2[3]);

	int tri_tri_intersect(float V0[3],float V1[3],float V2[3],
						  float U0[3],float U1[3],float U2[3]);

	int NoDivTriTriIsect(float V0[3],float V1[3],float V2[3],
						 float U0[3],float U1[3],float U2[3]);

	int tri_tri_intersect_with_isectline(float V0[3],float V1[3],float V2[3],
						 float U0[3],float U1[3],float U2[3],int *coplanar,
						 float isectpt1[3],float isectpt2[3]);

	//---------------------------------------------------------------------------
	//GEOMETRIC METHOD
	//

	float	geoPt2Line(NDVECTOR3* pt, NDVECTOR3* ptOnLine, NDVECTOR3* lineDir, float* t =NULL);
	float	geoPt2Ray(NDVECTOR3* pt, NDVECTOR3* lineStartPt, NDVECTOR3* lineDir, float* t =NULL);
	float	geoPt2Seg(NDVECTOR3* pt, NDVECTOR3* lineStartPt, NDVECTOR3* lineEndPt, float* t =NULL); //t[0 1]

	int		geoLineIntersect2D(NDVECTOR2* p0, NDVECTOR2* p0dir, 
							NDVECTOR2* p1, NDVECTOR2* p1dir, 
							float* t); //return 0:no intersection 1:a unique intersection 2:overlap
										//t (line0 length) from p0 to intersect pt

	bool    geoLineTriangleIntersect( NDVECTOR3* pTriArr, NDVECTOR3* pRayPt, NDVECTOR3* pRayDir, float* pOutIntersectLen =0, bool bTestCull =false);

	bool	geoPtInAABB( NDVECTOR3* pPt, NDVECTOR3* pAABBMax, NDVECTOR3* pAABBMin );
	float	geoPt2AABB( NDVECTOR3* pPt, NDVECTOR3* pAABBCenter, NDVECTOR3* pAABBHalfSz );

	void	NDPlaneFromPointNormal( NDVECTOR4* pOut, const NDVECTOR3* pPoint, const NDVECTOR3* pNormal );
	bool	NDPlaneIntersectLine( NDVECTOR3* pOutIntersectPt, const NDVECTOR4* pPlane, const NDVECTOR3* pLineP0, const NDVECTOR3* pLineP1 );
	float	NDPlaneDotNormal( const NDVECTOR4* pPlane, const NDVECTOR3* pVec );
	float	NDPlaneDotCoord( const NDVECTOR4* pPlane, const NDVECTOR3* pVec );


}//namespace



